home *** CD-ROM | disk | FTP | other *** search
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Filename: WindowsUpdates.vbs
- ' *** ------------------------------------------------------------------------------
- ' *** Description: Automatically downloads and installs relevant updates
- ' *** ------------------------------------------------------------------------------
- ' *** Version: 1.0
- ' *** Notes:
- ' *** ------------------------------------------------------------------------------
- ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
- ' *** ------------------------------------------------------------------------------
- ' ***
-
- ' ~~~
- ' ~~~ Force variables to be declared
- ' ~~~
- Option Explicit
-
- Dim I, I2, oSession, oSearcher, oSearchResult, oUpdate, oUpdatesToDownload, oUpdatesToInstall, oDownloader, oInstaller, oInstallationResult
- Dim oFileSystem, oLog
- dim oWinFolder
-
-
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Create objects
- ' ~~~ ------------------------------------------------------------------------------
- Set oSession = CreateObject("Microsoft.Update.Session")
- Set oSearcher = oSession.CreateupdateSearcher()
-
- Set oFileSystem = CreateObject("Scripting.FileSystemObject")
- Set oWinFolder = oFileSystem.GetSpecialFolder (0)
- Set oLog = oWinFolder.CreateTextFile("SCTWindowsUpdates.log", True)
-
- Public Function DoWindowsUpdates
-
- On Error Resume Next
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Search for updates
- ' ~~~ ------------------------------------------------------------------------------
- oLog.WriteLine FormatDateTime (Now) & " Searching for updates..." & vbCRLF
- oLog.WriteLine FormatDateTime (Now) & " List of applicable items on the machine:"
-
- I2=0
- For I = 0 To oSearchResult.Updates.Count-1
- Set oUpdate = oSearchResult.Updates.Item(I)
- I2=I2+1
- oLog.WriteLine I + 1 & "> " & oUpdate.Title
- Next
-
- If I2 = 0 Then
- oLog.WriteLine FormatDateTime (Now) & " There are no applicable updates."
- Exit Function
- End If
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Create collection of upates to download
- ' ~~~ ------------------------------------------------------------------------------
- oLog.WriteLine vbCRLF & FormatDateTime (Now) & " Creating collection of updates to download:"
- Set oUpdatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
-
- For I = 0 to oSearchResult.Updates.Count-1
- Set oUpdate = oSearchResult.Updates.Item(I)
- oLog.WriteLine I + 1 & "> adding: " & oUpdate.Title
- oUpdatesToDownload.Add(oUpdate)
- Next
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Download updates
- ' ~~~ ------------------------------------------------------------------------------
- oLog.WriteLine vbCRLF & FormatDateTime (Now) & " Downloading updates..."
-
- Set oDownloader = oSession.CreateUpdateDownloader()
- oDownloader.Updates = oUpdatesToDownload
- oDownloader.Download()
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Create a collection of downloaded updates to install
- ' ~~~ ------------------------------------------------------------------------------
- oLog.WriteLine vbCRLF & FormatDateTime (Now) & " Creating collection of downloaded updates to install:"
- Set oUpdatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
-
- For I = 0 To oSearchResult.Updates.Count-1
- Set oUpdate = oSearchResult.Updates.Item(I)
- oLog.WriteLine I + 1 & "> adding: " & oUpdate.Title
- oUpdatesToInstall.Add(oUpdate)
- Next
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Install updates
- ' ~~~ ------------------------------------------------------------------------------
- oLog.WriteLine FormatDateTime (Now) & " Installing updates..."
- Set oInstaller = oSession.CreateUpdateInstaller()
- oInstaller.Updates = oUpdatesToInstall
- oInstaller.ForceQuiet = true
- Set oInstallationResult = oInstaller.Install()
-
- ' ~~~ ------------------------------------------------------------------------------
- ' ~~~ Output results of install
- ' ~~~ ------------------------------------------------------------------------------
- oLog.WriteLine FormatDateTime (Now) & " Installation Result: " & oInstallationResult.ResultCode
- oLog.WriteLine FormatDateTime (Now) & " Reboot Required: " & oInstallationResult.RebootRequired & vbCRLF
- oLog.WriteLine FormatDateTime (Now) & " Listing of updates installed and individual installation results:"
-
- For I = 0 to oUpdatesToInstall.Count - 1
- oLog.WriteLine I + 1 & "> " & oUpdatesToInstall.Item(i).Title & ": " & oInstallationResult.GetUpdateResult(i).ResultCode
- Next
-
- End Function
-
-
-
- On Error Resume Next
-
- oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Update Rollups"
- Set oSearchResult = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '28BC880E-0592-4CBF-8F95-C79B17911D5F'")
- Call DoWindowsUpdates
- oLog.WriteLine vbCRLF & vbCRLF
-
-
- oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Security Updates"
- Set oSearchResult = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '0FA1201D-4330-4FA8-8AE9-B877473B6441'")
- Call DoWindowsUpdates
- oLog.WriteLine vbCRLF & vbCRLF
-
-
- oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Service Packs"
- Set oSearchResult = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains '68C5B0A3-D1A6-4553-AE49-01D3A7827828'")
- Call DoWindowsUpdates
- oLog.WriteLine vbCRLF & vbCRLF
-
-
- ' Definition Updates, for Windows Defender
- oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Definition Updates"
- Set oSearchResult = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains 'e0789628-ce08-4437-be74-2495b842f43b'")
- Call DoWindowsUpdates
- oLog.WriteLine vbCRLF & vbCRLF
-
- oLog.WriteLine FormatDateTime (Now) & " Downloading and Installing Critical Updates"
- Set oSearchResult = oSearcher.Search("IsInstalled=0 and Type='Software' and CategoryIDs contains 'e6cf1350-c01b-414d-a61f-263d14d133b4'")
- Call DoWindowsUpdates
- oLog.WriteLine vbCRLF & vbCRLF
-
- oLog.WriteLine FormatDateTime (Now) & " Updates Complete"
-
- oLog.Close
-